import ProTable, {ActionType} from '@ant-design/pro-table';
import React, {useRef} from 'react';
import {message, Modal, Popconfirm, Space} from "antd";
import {CouponLists} from "@/services/ant-design-pro/users";

const Coupon = (props) => {
  const {coupon,closeCoupon} = props;
  const actionRef = useRef<ActionType>();

  const send=(record)=>{
    console.log(record);
  }
  const columns=[
    {
      title: '优惠券名称',
      dataIndex:'title',
      align: 'center',
    },
    {
      title:'优惠券面值',
      search:false,
      dataIndex:'coupon_price',
      align: 'center',
    },
    {
      title:'优惠券最低消费',
      search:false,
      dataIndex:'use_min_price',
      align: 'center',
    },
    {
      title:'优惠券有效期限',
      search:false,
      dataIndex:'coupon_time',
      align: 'center',
    },
    {
      title:'操作',
      search:false,
      dataIndex: '',
      align: 'center',
      render:(_,record)=>{
        return (
          <a onClick={()=>{
            send(record)
          }}>
            <Popconfirm
              title="你确定要发送优惠券吗？"
              onConfirm={async (values)=>{

                actionRef.current?.reload()
                message.success('发送成功！')
              }}

              onCancel={async()=>{
                actionRef.current?.reload()
                message.success('取消成功！')
              }}
            >
              发送
            </Popconfirm>

          </a>
        )
      }
    }
  ]
  return (
    <div>
      <Modal
        visible={coupon}
        destroyOnClose={true}
        width={800}
        footer={null}
        onCancel={closeCoupon}
      >
        <ProTable
          columns={columns}
          actionRef={actionRef}
          // rowSelection={{}}
          request={async (params, sort, filter)=>{
            const {data, meta} = await CouponLists( {...params,...sort, ...filter} );
            return {
              data,
              success: true,
              total: meta.pagination.total
            }
          }}
          rowKey="id"
          search={{
            labelWidth: 'auto',
          }}
          dateFormatter="string"
        />
      </Modal>
    </div>
  );
};

export default Coupon;
